package com.zhuoyue.web.controller.system;

import com.zhuoyue.common.core.controller.BaseController;
import com.zhuoyue.common.core.domain.AjaxResult;
import com.zhuoyue.common.core.page.TableDataInfo;
import com.zhuoyue.common.utils.SecurityUtils;
import com.zhuoyue.common.utils.poi.ExcelUtil;
import com.zhuoyue.system.domain.SysContentPush;
import com.zhuoyue.system.service.ISysContentPushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 内容通知Controller
 *
 * @author zhanghui
 * @date 2021-08-24
 */
@RestController
@RequestMapping("/system/contentPush")
public class SysContentPushController extends BaseController {
    @Autowired
    private ISysContentPushService sysContentPushService;

    /**
     * 查询内容通知列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysContentPush sysContentPush) {
        startPage();
        List<SysContentPush> list = sysContentPushService.selectSysContentPushList(sysContentPush);
        return getDataTable(list);
    }

    /**
     * 导出内容通知列表
     */
    @GetMapping("/export")
    public AjaxResult export(SysContentPush sysContentPush) {
        List<SysContentPush> list = sysContentPushService.selectSysContentPushList(sysContentPush);
        ExcelUtil<SysContentPush> util = new ExcelUtil<SysContentPush>(SysContentPush.class);
        return util.exportExcel(list, "系统通知");
    }

    /**
     * 获取内容通知详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysContentPushService.selectSysContentPushById(id));
    }

    /**
     * 新增内容通知
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysContentPush sysContentPush) {
        sysContentPush.setCreateBy(SecurityUtils.getUsername());
        return toAjax(sysContentPushService.insertSysContentPush(sysContentPush));
    }

    /**
     * 修改内容通知
     */
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody SysContentPush sysContentPush) {
        sysContentPush.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(sysContentPushService.updateSysContentPush(sysContentPush));
    }

    /**
     * 删除内容通知
     */
    @DeleteMapping("/delete")
    public AjaxResult remove(Long id) {
        return toAjax(sysContentPushService.deleteSysContentPushById(id));
    }
}
